# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Mirco Tischler <mt-ml at gmx dot de>

_name=libostree
pkgname=ostree
pkgver=2021.4
_commit='09804f7a093b45adf4d36820fa5158990e89276d' # 2021.4
pkgrel=1
pkgdesc="Operating system and container binary deployment and upgrades"
url="https://ostree.readthedocs.org/en/latest/"
arch=('x86_64')
license=('GPL2')
depends=('fuse2' 'glibc' 'libgpg-error' 'libsodium' 'util-linux' 'openssl' 'xz'
'zlib')
makedepends=('avahi' 'e2fsprogs' 'git' 'glib2' 'gobject-introspection' 'gpgme'
'gtk-doc' 'libarchive' 'libsoup' libxslt 'mkinitcpio' 'python' 'systemd')
checkdepends=('cpio' 'elfutils' 'gjs' 'parallel' 'python-yaml' 'syslinux')
provides=('libostree-1.so')
source=("git+https://github.com/ostreedev/ostree#commit=${_commit}"
        "git+https://github.com/mendsley/bsdiff"
        "git+https://gitlab.gnome.org/GNOME/libglnx.git")
sha512sums=('SKIP'
            'SKIP'
            'SKIP')
b2sums=('SKIP'
        'SKIP'
        'SKIP')
# upstream ticket about chain of trust:
# https://github.com/ostreedev/ostree/issues/2349
validpgpkeys=('1CEC7A9DF7DA85ABEF843DC0A866D7CCAE087291') # Colin Walters <walters@redhat.com>

prepare() {
  cd "$pkgname"

  git submodule init
  git config --local submodule.bsdiff.url "$srcdir/bsdiff"
  git config --local submodule.libglnx.url "$srcdir/libglnx"
  git submodule update

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  cd "$pkgname"

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib \
    --with-builtin-grub2-mkconfig \
    --with-ed25519-libsodium \
    --with-dracut \
    --with-mkinitcpio \
    --with-openssl \
    --enable-experimental-api \
    --disable-static \
    --enable-gtk-doc

  # circumvent overlinking
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

  make
}

check() {
  cd "$pkgname"
  make check -k || echo "Known to fail: https://github.com/ostreedev/ostree/issues/2313"
}

package() {
  depends+=('libarchive.so' 'libavahi-client.so' 'libavahi-common.so'
  'libavahi-glib.so' 'libgio-2.0.so' 'libglib-2.0.so' 'libgobject-2.0.so'
  'libgpgme.so' 'libsoup-2.4.so' 'libsystemd.so')

  cd "$pkgname"
  make DESTDIR="$pkgdir" install
}
